package com.banshuibao.bsb_android.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.banshuibao.bsb_android.R;
import com.banshuibao.bsb_android.model.OfficeModel;
import com.banshuibao.bsb_android.util.ImageUtil;
import com.banshuibao.bsb_android.util.IntentManager;
import com.banshuibao.bsb_android.util.PriceUtil;

/**
 * Created by zyh on 2017/12/20.
 */

public class GoodsListAdapter extends MyBaseAdapter<OfficeModel.Data> {

    public GoodsListAdapter(Context context) {
        super(context);
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        OfficeViewHolder holder;
        if (view == null) {
            holder = new OfficeViewHolder();
            view = layoutInflater.inflate(R.layout.item_goods_list, viewGroup, false);
            holder.ad_iv = view.findViewById(R.id.img2);
            holder.title = view.findViewById(R.id.text2);
            holder.price = view.findViewById(R.id.price2);
            view.setTag(holder);
        } else
            holder = (OfficeViewHolder) view.getTag();
        final OfficeModel.Data item = getItem(i);
        if (item != null) {
            holder.title.setText(item.getTitle());
            if (item.getPrice() == 0) {
                holder.price.setTextSize(12);
                holder.price.setText("面议");
            } else {
                holder.price.setTextSize(13);
                holder.price.setText(PriceUtil.FormatDecimal(item.getPrice()));
            }
            ImageUtil.loadRoundImage(context, item.getLogImg(), holder.ad_iv, 20, 0);
            view.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    IntentManager.goGoodsDetailActivity(context, item.getUuid());
                }
            });
        }
        return view;
    }

    private class OfficeViewHolder {
        ImageView ad_iv;
        TextView title, price;
    }
}
